/**
 * Copyright &copy; 2016-2017 <a href="http://git.oschina.net/whoamien/backend_management">Backend Management</a> All rights reserved.
 */
package com.xw.app.model;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.xw.framework.base.dao.BaseUpdatableEntity;

/**
 * The Class SysDict.
 *
 * @author Xi Wei
 */
@Entity
@Table(name="sys_dict")
@DynamicUpdate(value=true)
@DynamicInsert(value=true)
public class SysDict extends BaseUpdatableEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6413775414819869267L;

	private Long systemId;
	private String dictCode;
	private String dictName;
	private String dictDesc;
	private int dictLevel = 1;
	private String parentCode;
	
	
	/**
	 * Gets the system id.
	 *
	 * @return the system id
	 */
	public Long getSystemId() {
		return systemId;
	}
	
	/**
	 * Sets the system id.
	 *
	 * @param systemId the new system id
	 */
	public void setSystemId(Long systemId) {
		this.systemId = systemId;
	}
	
	/**
	 * Gets the dict code.
	 *
	 * @return the dict code
	 */
	public String getDictCode() {
		return dictCode;
	}
	
	/**
	 * Sets the dict code.
	 *
	 * @param dictCode the new dict code
	 */
	public void setDictCode(String dictCode) {
		this.dictCode = dictCode;
	}
	
	/**
	 * Gets the dict name.
	 *
	 * @return the dict name
	 */
	public String getDictName() {
		return dictName;
	}
	
	/**
	 * Sets the dict name.
	 *
	 * @param dictName the new dict name
	 */
	public void setDictName(String dictName) {
		this.dictName = dictName;
	}
	
	/**
	 * Gets the dict desc.
	 *
	 * @return the dict desc
	 */
	public String getDictDesc() {
		return dictDesc;
	}
	
	/**
	 * Sets the dict desc.
	 *
	 * @param dictDesc the new dict desc
	 */
	public void setDictDesc(String dictDesc) {
		this.dictDesc = dictDesc;
	}
	
	/**
	 * Gets the dict level.
	 *
	 * @return the dict level
	 */
	public int getDictLevel() {
		return dictLevel;
	}
	
	/**
	 * Sets the dict level.
	 *
	 * @param dictLevel the new dict level
	 */
	public void setDictLevel(int dictLevel) {
		this.dictLevel = dictLevel;
	}
	
	/**
	 * Gets the parent code.
	 *
	 * @return the parent code
	 */
	public String getParentCode() {
		return parentCode;
	}
	
	/**
	 * Sets the parent code.
	 *
	 * @param parentCode the new parent code
	 */
	public void setParentCode(String parentCode) {
		this.parentCode = parentCode;
	}
	
	@ManyToOne
	@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
	@JoinColumn(name = "parent_id", nullable = true)
	@JsonIgnore
	private SysDict parent;
	@OneToMany(mappedBy="parent", cascade={javax.persistence.CascadeType.ALL}, fetch=FetchType.LAZY)
	@JsonIgnore
	private List<SysDict> subDictList = Lists.newArrayList();
	
	/**
	 * Gets the parent.
	 *
	 * @return the parent
	 */
	public SysDict getParent() {
		return parent;
	}
	
	/**
	 * Sets the parent.
	 *
	 * @param parent the new parent
	 */
	public void setParent(SysDict parent) {
		this.parent = parent;
	}
	
	/**
	 * Gets the sub dict list.
	 *
	 * @return the sub dict list
	 */
	public List<SysDict> getSubDictList() {
		return subDictList;
	}
	
	/**
	 * Sets the sub dict list.
	 *
	 * @param subDictList the new sub dict list
	 */
	public void setSubDictList(List<SysDict> subDictList) {
		this.subDictList = subDictList;
	}
	
	/**
	 * Checks if is checks for parent.
	 *
	 * @return true, if is checks for parent
	 */
	@Transient
	public boolean isHasParent(){
		return parent == null ? false:true;
	}
	
	
}
